<%- if scope[:repository_configuration] -%>
<fieldset>
    <legend><span><%= scope[:plugin_id].upcase %> Repository Configuration</span></legend>
    <%- scope[:repository_configuration].properties.each_with_index do |package_property_model, index| %>
        <%= fields_for "package_repository[#{com.thoughtworks.go.domain.config.Configuration::CONFIGURATION}]", package_property_model, :index => "#{index}" do |var_form| %>
                <div class="field required">
                    <%= var_form.fields_for com.thoughtworks.go.domain.config.ConfigurationProperty::CONFIGURATION_KEY, package_property_model do |configuration_key| %>
                        <%= configuration_key.hidden_field com.thoughtworks.go.domain.config.ConfigurationKey::NAME %>
                        <%- if package_property_model.is_mandatory -%>
                            <%= required_label(configuration_key, "value", package_property_model.display_name) -%>
                        <%- else -%>
                            <%= label(configuration_key, "value", package_property_model.display_name) -%>
                        <%- end -%>
                    <%- end -%>
                    <% if package_property_model.is_secure %>
                        <%= var_form.fields_for com.thoughtworks.go.domain.config.ConfigurationProperty::CONFIGURATION_VALUE, package_property_model do |configuration_value| %>
                            <%- if scope[:isNewRepo] %>
                                <%= configuration_value.password_field com.thoughtworks.go.domain.config.ConfigurationValue::VALUE, :id => "secure_field_#{index}" %>
                            <%- else -%>
                                <%= configuration_value.password_field com.thoughtworks.go.domain.config.ConfigurationValue::VALUE, :readonly => "readonly", :id => "secure_field_#{index}" %>
                            <%- end -%>
                        <%- end -%>
                        <%= var_form.fields_for com.thoughtworks.go.domain.config.ConfigurationProperty::ENCRYPTED_VALUE, package_property_model do |configuration_value| %>
                            <%= configuration_value.hidden_field com.thoughtworks.go.domain.config.EncryptedConfigurationValue::VALUE, :id => "hidden_field_#{index}" -%>
                            <%- if !scope[:isNewRepo] %>
                                <div>
                                    <% chkbox = check_box_tag("package_repository[#{com.thoughtworks.go.domain.config.Configuration::CONFIGURATION}][#{index}][#{com.thoughtworks.go.domain.config.ConfigurationProperty::IS_CHANGED}]", "1", false, {:class => "password_changed", :id => "checkbox_field_#{index}"}) -%>
                                    <label for="checkbox_field_<%==index-%>" class="checkbox"><%==chkbox-%><span>Change <%==package_property_model.display_name-%></span></label>
                                    <script type="text/javascript">
                                        var passwordField = "<%="#secure_field_#{index}"-%>";
                                        var checkBox = "<%="#checkbox_field_#{index}"-%>";
                                        var hiddenField = "<%="#hidden_field_#{index}"-%>";
                                        jQuery(checkBox).click(function () {
                                            if (jQuery(this).is(":checked")) {
                                                jQuery(passwordField).removeAttr('readonly');
                                                jQuery(passwordField).val('');
                                            }
                                            else {
                                                jQuery(passwordField).attr('readonly', 'readonly');
                                                jQuery(passwordField).val(jQuery(hiddenField).val());
                                            }

                                        });
                                    </script>
                                </div>
                            <%- else -%>
                                <%= hidden_field_tag("package_repository[#{com.thoughtworks.go.domain.config.Configuration::CONFIGURATION}][#{index}][#{com.thoughtworks.go.domain.config.ConfigurationProperty::IS_CHANGED}]","1") %>
                            <%- end -%>
                        <% end %>
                    <% else %>
                        <%= var_form.fields_for com.thoughtworks.go.domain.config.ConfigurationProperty::CONFIGURATION_VALUE, package_property_model do |configuration_value| %>
                            <%= configuration_value.text_field com.thoughtworks.go.domain.config.ConfigurationValue::VALUE %>
                        <% end %>
                    <%- end -%>
                    </div>
            <% end %>
    <% end %>
    <div class="field no-label-element">
        <%= submit_button('CHECK CONNECTION', :type => "button", :id => "check_connection") -%>
        <span id="repository_connection_message"></span>
    </div>
</fieldset>
<%- end -%>




